import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

//
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

const Home = () => import("../views/home/Home");
const Cart = () => import("../views/cart/Cart");
const Profile = () => import("../views/profile/Profile");
const Category = () => import("../views/category/Category");
const Detail = () => import("../views/detail/Detail");
const AccountLogin = () => import("../views/profile/childComps/AccountLogin");
const QQLogin = () => import("../views/profile/childComps/QQLogin");
const AboutUs = () => import("../views/profile/childComps/AboutUs");
const History = () => import("../views/profile/childComps/History");
const Order = () => import("../views/order/Order");
const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    component: Home,
  },
  {
    path: "/cart",
    component: Cart,
  },
  {
    path: "/profile",
    component: Profile,
  },
  {
    path: "/category",
    component: Category,
  },
  {
    path: "/detail/:iid",
    component: Detail,
  },
  {
    path: "/login/qq",
    component: QQLogin,
  },
  {
    path: "/login/account",
    component: AccountLogin,
  },
  {
    path: "/about",
    component: AboutUs,
  },
  {
    path: "/history",
    component: History,
  },
  {
    path: "/order",
    component: Order,
  },
];

const router = new VueRouter({
  routes,
  mode: "hash",
  scrollBehavior() {
    return { x: 0, y: 0 };
  },
});
export default router;
